package com.c5c6;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/ServletConfigTest")

public class ServletConfigTest extends HttpServlet {
    private ServletConfig config;
    public ServletConfigTest() {
        super();
    }
    @Override
    public void destroy() {
        super.destroy();
    }
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        this.config = config;
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String charset = this.config.getInitParameter("charset");
        response.setCharacterEncoding(charset);
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>ServletConfig</title></head>");
        out.println("<body>");
        out.println("获取initParamServlet的初始化参数\"encoding\"的字符串值："+charset);
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

}
